import threading
from pynput import mouse
from .MouseClickListener import MouseClickListener
from .MouseLongPressListener import MouseLongPressListener
from .MouseDragListener import MouseDragListener
from .MouseAreaListener import MouseAreaListener


def listenClick(event):
    listener = MouseClickListener(event)
    listener.startListen()


def listenLongPress(event):
    listener = MouseLongPressListener(event)
    listener.startListen()


def listenDrag(event):
    listener = MouseDragListener(event)
    listener.startListen()


def listenArea(event):
    listener = MouseAreaListener(event)
    listener.startListen()


def listen(event):
    r = threading.Thread(target=_listen, args=(event,))
    r.start()


def _listen(event):
    with mouse.Listener(on_click=event) as listener:
        listener.join()
        listener.stop()
